const { message } = require("antd");

const customFetch = async (url, options = {}) => {
  try {
    const response = await fetch(url, options);

    // 检查响应状态
    if (!response.ok) {
      throw new Error(`HTTP error! status: ${response.status}`);
    }

    // 解析 JSON 数据
    const data = await response.json();

    if (data.code !== 2000) {
      throw new Error(data.msg);
    }
    return data;
  } catch (error) {
    // 处理错误
    message.error('Fetch Error:' + error);
    throw error;
  }
};

export default customFetch;